﻿using System.Linq;
using uTrade.Core;

namespace uTrade.Data.Stock
{
    public class DataAccessService
    {
        public static TransDatas GetStockData(Category category, string symbol, int start, int count)
        {
            TransDatas transBars = new TransDatas();
            StockSecurityBar[] securityBars = TdxTest.GetSecurityBars(Category.Day1, Market.Shenzhen, symbol, start, count);
            Bar[] bars = securityBars.Cast<StockSecurityBar>().Select(s => s.ToBar()).ToArray();
            transBars.Interval = (int)category;
            transBars.Symbol = symbol;
            StockInfo stockInfo = StockInfoManager.GetModel(symbol);
            Core.StockInfo stock = new Core.StockInfo
            {
                Symbol = stockInfo.Symbol,
                Name = stockInfo.Name,
                Type = stockInfo.Type,
                OneHand = stockInfo.OneHand,
                PointIndex = stockInfo.PointIndex,
                YestClose = stockInfo.YestClose,
                Favorite = stockInfo.Favorite
            };
            transBars.StockInfo = stock;
            transBars.LoadData(bars);
            return transBars;
        }
    }
}